<template>
    <div class="reCharge_page">
    
      <van-nav-bar
        title="搜索用户"
        left-arrow
        @click-left="goBack"
        left-text="返回"
        />
        <van-search
          v-model="friendId"
          show-action
          placeholder="请输入近聘号／手机号"
          @search="onSearch"
          type='number'
        >
          <template #action>
            <div @click="onSearch">搜索</div>
          </template>
        </van-search>

        <div class="list_content">
          <div class='list' v-for="(item,index) in searchUserList" :key='index'>
            <div class="left">
              <img :src="item.avatar" style='width:100%;height:100%' alt="">
            </div>
            <div class='right'>
              <div class="up">{{item.nick_name}}</div>
              <div class="down">{{item.id}}</div>
            </div>
            <div @click="addUserFired(item)" style='padding:10px;borderRadius:5px;fontWeight:bold'>添加</div>
          </div>
        </div>
    </div>
</template>

<script>
import { Toast } from "vant";
  export default {
    name: 'reCharge',
    data(){
      return {
        smtype:true,
        friendId:'',
        userInfo:'',
        searchUserList:[]
      }
    },
    components:{

    },
    created(){
      let userInfo = localStorage.getItem('userInfo')
      this.userInfo = JSON.parse(userInfo)
      if(this.$route.params.account_scan){
        let type = this.$route.params.type
        this.friendId = this.$route.params.account_scan
        this.onSearch(type)
      }

    },
    methods:{

       goBack(){
           this.$router.go('-1')
       },
       onSearch(type) {
         
          let params = {
            ids:'',
            account:this.friendId
          }
          this.$api.user.GetUser(params).then(res => {
              if (res.code === 200) {
                console.log(JSON.parse(res.data))
                // this.searchUserList = JSON.parse(res.data)
                if(JSON.parse(res.data).length>0){
                  this.$router.push({
                    name: 'friendInfo',
                    params: {
                      jobObj: JSON.stringify(JSON.parse(res.data)[0]),
                      type:type
                    }
                  })
                }else{
                  Toast('未查询到该用户')
                }

              }
          })
        },
        onCancel() {

        },





      },


  }
</script>

<style scoped lang='scss'>
  .title{
    height: 300px;
    width: 300px;
    text-align: left;
    font-size: 18px;
    margin: 20px auto 0;
  }
  .list{
    padding:10px;
    display: flex;
    .left{
      width:30px;
      height:30px;
      border-radius: 5px;
      margin-right: 10px;
    }
  }
</style>
